import math
import random


def calcPri2(x):
    return len(bin(x)) - 3;


def calcPri10(x):
    return len(str(x)) - 1;


def pri10(x, a=32):
    if int(calcPri2(x)) < a:
        print(f'SCNS_ASSERT_ON_RUN(scnsLog10FloorUint{a}({x}ULL)=={int(calcPri10(x))});')


def pri2(x, a=32):
    if int(calcPri2(x)) < a:
        print(f'SCNS_ASSERT_ON_RUN(scnsLog2FloorUint{a}({x}ULL)=={int(calcPri2(x))});')


def erfen(l=0, r=9, hex=10):
    if l == r:
        return f'return {l};'
    else:
        m = (l + r) // 2
        return f'if(x<0X{pow(hex, (m + 1)):X}ULL){{' + erfen(l, m, hex) + '}else{' + erfen(m + 1, r, hex) + '}'


if __name__ == '__main__':
    s = [0, 0XFF, 0XFF + 1, 0XFFFF, 0XFFFF + 1, 0XFFFFFFFF, 0XFFFFFFFF + 1, 0XFFFFFFFFFFFFFFFF]
    for i in range(0, 64):
        s.append(10 ** i)
        s.append(10 ** i - 1)
        s.append(10 ** i + 1)
        s.append(2 ** i + 1)
        s.append(2 ** i)
        s.append(2 ** i - 1)
        for j in range(0, 5):
            s.append(int((random.random()) * (10 ** (i + 1))))
            s.append(int((random.random()) * (2 ** (i + 1))))
    for x in sorted(set(s)):
        pri10(x, 32)
    for x in sorted(set(s)):
        pri10(x, 64)

    for x in sorted(set(s)):
        pri2(x, 32)
    for x in sorted(set(s)):
        pri2(x, 64)

    print(0XFFFFFFFFFFFFFFFF)

    print(erfen(0, 9, 10))
    print(erfen(0, 19, 10))
    print(erfen(0, 31, 2))
    print(erfen(0, 63, 2))

    s=''
    for  i in range(0,64):
        s+=f'{random.randint(0,255):#02X},'
    print(s)
